package com.central.apps.handler.purchase;

import com.alibaba.fastjson.JSONObject;
import com.central.app.service.HandlerService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class ContractSigning {
    @Autowired
    private HandlerService handlerService;
    @PostMapping("/contractSi")
    public String contract (@RequestBody Map<String,Object> params) throws Exception{
        JSONObject object = new JSONObject();
        object.put("code","0");
        String id = MapUtils.getString(params, "id");
        //查询提报信息
        List<Map<String, Object>> bySql = handlerService.findBySql("SELECT ponum,status,createuserdesc,concode,conname,contype,deptcode,projectnum,sptask,projectname,taskid,createtime\n" +
                "\tfrom gq_po where id ='"+id+"'");
        if (CollectionUtils.isNotEmpty(bySql)){
            for (int i=0;i<bySql.size();i++) {
                Map<String, Object> map = bySql.get(0);
                String ponum = MapUtils.getString(map, "ponum");
                String status = MapUtils.getString(map, "status");
                String createuserdesc = MapUtils.getString(map, "createuserdesc");
                String concode = MapUtils.getString(map, "concode");
                String conname = MapUtils.getString(map, "conname");
                String contype = MapUtils.getString(map, "contype");
                String deptcode = MapUtils.getString(map, "deptcode");
                String projectnum = MapUtils.getString(map, "projectnum");
                String sptask = MapUtils.getString(map, "sptask");
                String projectname = MapUtils.getString(map, "projectname");
                String taskid = MapUtils.getString(map, "taskid");
                String createtime = MapUtils.getString(map, "createtime");
                HashMap<String, Object> hashMap = new HashMap<>();
                hashMap.put("purchasenum",ponum);
                hashMap.put("createuserdesc",createuserdesc);
                hashMap.put("maincon",concode);
                hashMap.put("relationname",conname);
                hashMap.put("contype",contype);
                hashMap.put("deptcode",deptcode);
                hashMap.put("relationprocode",projectnum);
                hashMap.put("relationproname",projectname);
                hashMap.put("taskid",taskid);
                hashMap.put("taskname",sptask);
                hashMap.put("createtime",createtime);
                HashMap<String, Object> hashMap1 = new HashMap<>();
                handlerService.addBizNum("consignsApp","gq_consigns",hashMap1);
                String concode1 = (String) hashMap1.get("concode");
                hashMap.put("concode",concode1);
                handlerService.insert("gq_consigns",hashMap);

            }
        }
        return object.toString();
    }

}
